/**
 * FileSelectorAdapter.java
 * @author ChungPV1 
 *	
 */
package com.ghc.androidexample.share;

import com.ghc.androidexample.R;
import com.ghc.androidexample.R.id;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

/**
 * @author ChungPV1
 * 
 */
public class FileSelectorAdapter extends ArrayAdapter<String> {

	private Context mContext;
	private int mResource;

	/**
	 * @param context
	 * @param resource
	 * @param objects
	 */
	public FileSelectorAdapter(Context context, int resource, String[] objects) {
		super(context, resource, objects);

		mResource = resource;
		mContext = context;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHoder holder = null;
		if (convertView == null) {
			LayoutInflater inflater = (LayoutInflater) mContext
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			convertView = inflater.inflate(mResource, null);
			holder = new ViewHoder();
			holder.mTvText = (TextView) convertView
					.findViewById(R.id.tvFile_Text);
			convertView.setTag(holder);
		}
		holder = (ViewHoder) convertView.getTag();

		String item = getItem(position);
		if (!TextUtils.isEmpty(item)) {
			holder.mTvText.setText(item.substring(item.lastIndexOf("/")));
		}

		return convertView;
	}

	private static class ViewHoder {
		private TextView mTvText;
	}

}
